// Copyright (c) 2018 Muhammad M. Imtiaz

// This Work is subject to the terms of the Universal Permissive License,
// Version 1.0. If a copy of the licence was not distributed with this Work,
// you can obtain one at <https://oss.oracle.com/licenses/upl/>.

/**
 * Muhammad M. Imtiaz
 * Friday 5 October 2018
 * Informs individuals about overdue books that have been checked out of a library.
 **/

public class Fines {
    
    public static void main(String[] args) {
	String[] nameInfo;
	String title;
	String dateCheckedOut;
	int daysOverdue;
	double dailyFine;
	java.util.Scanner scanner = new java.util.Scanner(System.in);

	String name;
	String userId;
	double totalFine;

	System.out.print("Enter name (Last, First) and Social Security Number (###-##-####): ");
	nameInfo = scanner.nextLine().split(" ");
	name = nameInfo[0] + " " + nameInfo[1];
	userId = nameInfo[0].substring(0, Math.min(5, nameInfo[0].length() - (nameInfo[0].endsWith(",") ? 1 : 0))) +
	    nameInfo[1].substring(0, Math.min(3, nameInfo[1].length())) +
	    "-" +
	    nameInfo[2].substring(7, 11);
	System.out.println();

	System.out.print("Enter the title of the book: ");
	title = scanner.nextLine();
	System.out.println();

	System.out.print("Enter the date checked out (mm/dd/yyyy): ");
	dateCheckedOut = scanner.nextLine();
	System.out.println();

	System.out.print("Days late: ");
	daysOverdue = scanner.nextInt();
	System.out.print("Daily fine: ");
	dailyFine = scanner.nextDouble();
	totalFine = daysOverdue * dailyFine;
        System.out.println();
	System.out.println();

	System.out.println("To: " + name + "\tAccount: " + userId);
	System.out.println("From: mona");
	System.out.println("Subject: Overdue Notice");
	System.out.println("============================================================");
	System.out.println(title + " was checked out on: " + dateCheckedOut);
	System.out.println("This book is currently " + daysOverdue + " days late.");
	System.out.println("Your fine has accumulated to: " + totalFine);
    }
    
}
